import { inject, observer } from 'mobx-react';
import CoworkRichText from '../../../public/CoworkRichText';
import { toJS } from 'mobx';
import isFunction from 'lodash/isFunction';
import {
  WeaTab,
  WeaNewScroll,
  WeaCheckbox,
  WeaAlertPage,
  WeaSearchGroup,
  WeaTools,
  WeaFormItem,
  WeaLocaleProvider,
  WeaDropdown,
} from 'ecCom';
import { WeaSwitch } from 'comsMobx';
import { Button, Pagination, message, Spin, Modal } from 'antd';
import { createMarkMenu } from '../../../util/CoworkUtil';

const getLabel = WeaLocaleProvider.getLabel;

import LogDialog from '../dialog/CoworkLogDialog';
import Resource from './Resource';
import CoworkFloorDialog from '../dialog/CoworkFloorDialog';
import NewCowork from '../dialog/NewCowork';
import Detail from './Detail';
import ReplyList from './ReplyList';
import MyReplyList from './MyReplyList';
import Stat from './Stat';
import InvitedDialog from './InvitedDialog';
import Participation from '../dialog/Participation';

const storeMapKey = 2; // 当前页面回去 新建编辑协作 store的key
const { viewer } = WeaTools;

class SearchForm extends React.Component {
  constructor(props) {
    super(props);
  }

  componentDidMount() {
    this.props.initFunc && this.props.initFunc(this);
  }

  onEnterSearch = () => {
    if (
      this.props.onEnterSearch &&
      typeof this.props.onEnterSearch === 'function'
    ) {
      this.props.onEnterSearch();
    }
  };

  render() {
    const { conditioninfo = [], form } = this.props;
    let group = [];
    if (form.isFormInit) {
      conditioninfo.map((c) => {
        let items = [];
        c.items.map((fields) => {
          items.push({
            com: (
              <WeaFormItem
                ecId={`${
                  (this && this.props && this.props.ecId) || ''
                }_WeaFormItem@9rv31m@${fields.domkey[0]}`}
                label={`${fields.label}`}
                labelCol={{ span: `${fields.labelcol}` }}
                wrapperCol={{ span: `${fields.fieldcol}` }}
              >
                <WeaSwitch
                  ecId={`${
                    (this && this.props && this.props.ecId) || ''
                  }_WeaSwitch@png39r@${fields.domkey[0]}`}
                  fieldConfig={fields}
                  form={form}
                  onEnterSearch={this.onEnterSearch}
                />
              </WeaFormItem>
            ),
            colSpan: 1,
          });
        });
        group.push(
          <WeaSearchGroup
            ecId={`${
              (this && this.props && this.props.ecId) || ''
            }_WeaSearchGroup@0uyn2k@group`}
            needTigger={true}
            title={c.title}
            showGroup={c.defaultshow}
            items={items}
          />,
        );
      });
    }
    return <div>{group}</div>;
  }

  clear = () => {
    this.props.form.resetConditionValue();
  };
}

@inject('coworkMainStore', 'coworkStoreMap')
@observer
class CoworkContent extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      // showSearchAd: false,
      // tabKey: 'list',
      // page: {
      //   current: 1,
      //   total: 0,
      //   showQuickJumper: true
      // },
      // edit: false,//编辑状态
      visiable: false, // log
      value: '1',
      isScrollTop: false,
      invitedVisible: false,
      participationVisible: false,
      participationType: '',
    };
  }

  componentDidMount() {
    this.props.coworkMainStore.initDetailParams();
    this.props.coworkMainStore.content.searchForm.resetForm(); // 切换协作页面时清空高级搜索表单数据
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.coworkId !== this.props.coworkId) {
      this.props.coworkMainStore.initDetailParams();
      this.props.coworkMainStore.content.searchForm.resetForm(); // 切换协作页面时清空高级搜索表单数据
      // this.setState({
      //   tabKey: 'list',
      //   edit: false
      // });
    }
    if (nextProps.coworkId != this.props.coworkId) {
      this.scrollToTop();
    }
  }

  componentDidUpdate() {
    jQuery(document)
      .off('keydown', '', this.onKeyDown)
      .on('keydown', '', this.onKeyDown);
    this.setContent();
  }

  componentWillUnmount() {
    const {
      coworkMainStore: { setContentParams, content },
    } = this.props;
    setContentParams({ page: { ...content.page, current: 1 } });
  }

  onImgs = (arr) => {
    Array.from(arr).forEach((img) => {
      img.onload = () => {
        img.setAttribute('data-imgsrc', img.src);
        img.setAttribute('class', 'formImgPlay');
        img.onclick = viewer;
      };
    });
  };

  setContent = () => {
    let content_img = document.querySelectorAll(
      '.cowork-content-text-main img',
    ); // 详情内容中的img
    let list_img = document.querySelectorAll(
      '.cowork-reply-remark .wea-cl-content img',
    ); // 交流列表中的img
    this.onImgs(content_img);
    this.onImgs(list_img);
  };

  handleScroll = () => {
    if (this.refs.scroll.getScrollTop() > 0) {
      this.setState({ isScrollTop: true });
    } else if (this.refs.scroll.getScrollTop() == 0) {
      this.setState({ isScrollTop: false });
    }
  };

  getCoworkDetailRef = ref => (this.coworkDetail = ref);

  onCommuFill = () => {
    this.props.coworkMainStore.setDetailParams({
      edit: true,
    });
  };

  saveCallback = () =>
    this.coworkDetail && this.coworkDetail.wrappedInstance.updateShow();

  onSearchChange = v =>
    this.props.coworkMainStore.content.searchForm.updateFields({
      srchcontent: v,
    });
  render() {
    const { coworkMainStore } = this.props;
    let {
      content,
      config,
      markItemAsType,
      deleteCoworkLabels,
      detailParams,
      isEllipse,
      participationStore,
    } = coworkMainStore;
    const { searchForm } = content;
    content = toJS(content);
    config = toJS(config);
    let { discussSearch = {} } = config,
      { conditioninfo = [] } = discussSearch;
    let { page, checkAll, batchOperate, pendApprove } = content;
    let con = content.cowork,
      itemsVO = (con && con.itemsVO) || {},
      { status } = itemsVO,
      coworkContentId = content.id,
      labelList = config.labelList,
      { coworkBaseSettingMap = {} } = con || {};
    let { coworkstate } = coworkBaseSettingMap;
    let { srchcontent } = searchForm.getFormParams();
    let canReply = status != '2' || coworkstate == '1'; // 协作不是结束状态，或者结束状态也能回复，此时可以发表交流或评论。
    const { showSearchAd, tabKey, edit } = detailParams;
    if (
      itemsVO &&
      itemsVO.approvalAtatus == '1' &&
      con &&
      con.canApproval.toString() !== '1'
    ) {
      return (
        <div
          className={`wea-cowork-content ${
            (tabKey == 'list' || tabKey == 'my') && 'cowork-list-scroll'
          }`}
        >
          <WeaAlertPage
            ecId={`${
              (this && this.props && this.props.ecId) || ''
            }_WeaAlertPage@ibk424`}
          >
            <div>
              <h1 style={{ color: 'red' }}>
                {getLabel('513538', '该协作正处于待审批状态')}
              </h1>
              <h3>{getLabel('513539', '您不是协作管理员，暂无权限查看')}</h3>
            </div>
          </WeaAlertPage>
        </div>
      );
    }
    return (
      <div
        className={`wea-cowork-content ${
          (tabKey == 'list' || tabKey == 'my') && 'cowork-list-scroll'
        }`}
      >
        {content.loading ? (
          <div className="wea-cowork-con">
            <Spin
              ecId={`${
                (this && this.props && this.props.ecId) || ''
              }_Spin@oz9g1k`}
              className="cowork-con-spin"
              size="large"
            />
          </div>
        ) : con && con.viewRight == 1 ? (
          [
            <div style={{ height: '100%' }}>
              <div
                ref="shadow"
                className={`cowork-content-detail wea-f14 ${
                  this.state.isScrollTop && 'isShadow'
                }`}
              >
                <span className="cowork-content-detail-text wea-f14">
                  {getLabel(382645, '协作详情')}
                </span>
                <div>
                  <WeaDropdown
                    ecId={`${
                      (this && this.props && this.props.ecId) || ''
                    }_WeaDropdown@rer56j@mark`}
                    className="cowork-content-detail-btn"
                    overlay={createMarkMenu(labelList, this.mark)}
                  >
                    {getLabel(81293, '标记为')}...
                  </WeaDropdown>
                  {con.canEdit && con.canEdit == 1 ? (
                    <Button
                      ecId={`${
                        (this && this.props && this.props.ecId) || ''
                      }_Button@3184uo@edit`}
                      className="cowork-content-detail-btn"
                      onClick={this.edit}
                    >
                      {getLabel(93, '编辑')}
                    </Button>
                  ) : null}
                  {con.canEdit &&
                  con.canEdit == 1 &&
                  con.itemsVO.status == '2' ? (
                    <Button
                      ecId={`${
                        (this && this.props && this.props.ecId) || ''
                      }_Button@y91vwv@open`}
                      className="cowork-content-detail-btn"
                      onClick={() =>
                        this.operateCoworkItem(coworkContentId, 'open')
                      }
                    >
                      {getLabel(360, '打开')}
                    </Button>
                  ) : null}
                  {con.canEdit &&
                  con.canEdit == 1 &&
                  con.itemsVO.status == '1' ? (
                    <Button
                      ecId={`${
                        (this && this.props && this.props.ecId) || ''
                      }_Button@kgjngy@end`}
                      className="cowork-content-detail-btn"
                      onClick={() =>
                        this.operateCoworkItem(coworkContentId, 'end')
                      }
                    >
                      {getLabel(405, '结束')}
                    </Button>
                  ) : null}
                  {con.canInvite && con.canInvite == '1' ? (
                    <Button
                      ecId={`${
                        (this && this.props && this.props.ecId) || ''
                      }_Button@ozizko@invite`}
                      className="cowork-content-detail-btn"
                      onClick={() =>
                        this.operateCoworkItem(coworkContentId, 'invite')
                      }
                    >
                      {getLabel('516505', '邀请加入')}
                    </Button>
                  ) : null}
                  <Button
                    ecId={`${
                      (this && this.props && this.props.ecId) || ''
                    }_Button@g7e7z3@log`}
                    onClick={() => {
                      this.showLogDialog(true);
                    }}
                    className="cowork-content-detail-btn"
                  >
                    {getLabel(17480, '查看日志')}
                  </Button>
                  <a href={con && con.exportUrl} target="_blank">
                    <Button
                      ecId={`${
                        (this && this.props && this.props.ecId) || ''
                      }_Button@t6q187@export`}
                      className="cowork-content-detail-btn"
                    >{`${getLabel(17416, '导出')}${getLabel(
                      15153,
                      '相关交流',
                    )}`}</Button>
                  </a>
                  {con.canQuit && con.canQuit == 1 ? (
                    <Button
                      ecId={`${
                        (this && this.props && this.props.ecId) || ''
                      }_Button@avdgo3@quit`}
                      className="cowork-content-detail-btn"
                      onClick={this.quitCowork}
                    >
                      {getLabel('513402', '退出协作')}
                    </Button>
                  ) : null}
                </div>
              </div>

              <div style={{ height: '100%', paddingBottom: 90 }}>
                <WeaNewScroll
                  ecId={`${
                    (this && this.props && this.props.ecId) || ''
                  }_WeaNewScroll@ow9v5h@detail`}
                  ref="scroll"
                  toTop={tabKey == 'list'}
                  height={'100%'}
                  onScroll={this.handleScroll}
                >
                  <Detail
                    ecId={`${
                      (this && this.props && this.props.ecId) || ''
                    }_Detail@bpdpqc@detail`}
                    content={content}
                    labelList={labelList}
                    markItemAsType={markItemAsType}
                    deleteCoworkLabels={deleteCoworkLabels}
                    // operateCoworkItem={operateCoworkItem}
                    ref={this.getCoworkDetailRef}
                    isEllipse={isEllipse}
                    setEllipse={this.setEllipse}
                  />
                  <div className="greyDiv" style={{ height: 10 }} />
                  {canReply && [
                    edit && (
                      <div className="cowork-grey-submit">
                        <CoworkRichText
                          ecId={`${
                            (this && this.props && this.props.ecId) || ''
                          }_CoworkRichText@6hqpru@rich`}
                          ref="richText"
                          hasSubmit={true}
                          submit={this.submitInEdit}
                          cancel={this.cancel}
                          approvalStatus={itemsVO.approvalAtatus}
                          isCanAnonymous={itemsVO.isAnonymous}
                          isApproval={itemsVO.isApproval}
                          isCoworkTypeApprove={con.isCoworkTypeApprove}
                          editType="discuss"
                          id="editId"
                        />
                      </div>
                    ),
                    edit || (
                      <div
                        className="cowork-content-msg wea-f12"
                        onClick={this.onCommuFill}
                      >
                        <b />
                        <em className="icon-coms-edit" />
                        <span>{getLabel(389454, '请填写交流内容')}</span>
                      </div>
                    ),
                    <div className="greyDiv" style={{ height: 10 }} />,
                  ]}
                  <div className="wea-cowork-content-list">
                    <WeaTab
                      ecId={`${
                        (this && this.props && this.props.ecId) || ''
                      }_WeaTab@xhjh87@tablist`}
                      datas={[
                        { title: getLabel(15153, '相关交流'), key: 'list' },
                        {
                          titleText: getLabel(32572, '与我相关'),
                          title: (
                            <div className="cowork-my" onClick={this.dotClick}>
                              {getLabel(32572, '与我相关')}
                              <span
                                className={
                                  con && con.isRead == '1'
                                    ? 'cowork-my-dot'
                                    : 'cowork-my-dotHide'
                                }
                              />
                            </div>
                          ),
                          key: 'my',
                        },
                        { title: getLabel(83274, '参与情况'), key: 'stat' },
                        { title: getLabel(84399, '相关资源'), key: 'resource' },
                      ]}
                      size="small"
                      keyParam="key"
                      leftStyle={{ width: '44%' }}
                      rightStyle={{ width: '56%' }}
                      selectedKey={tabKey}
                      onChange={this.changeTabKey}
                      searchType={tabKey == 'list' ? 'base,advanced' : ''}
                      buttons={
                        tabKey == 'list' && con.canEdit == 1
                          ? [
                              <span>
                                <span
                                  className={`batch-oper-button icon-cooperation-BatchOperation ${
                                    batchOperate && 'cur'
                                  }`}
                                  title={getLabel(31914, '批量操作')}
                                  onClick={coworkMainStore.setBatchOperate}
                                />
                                {con.canApproval == 1 && (
                                  <span
                                    className={`batch-oper-button icon-cooperation-PendingApproval ${
                                      pendApprove && 'cur'
                                    }`}
                                    title={getLabel(2242, '待审批')}
                                    onClick={coworkMainStore.setPendApprove}
                                  />
                                )}
                              </span>,
                            ]
                          : []
                      }
                      onSearch={this.search}
                      searchsBaseValue={srchcontent}
                      onSearchChange={this.onSearchChange}
                      showSearchAd={showSearchAd}
                      setShowSearchAd={this.setShowSearchAd}
                      hasMask={false}
                      searchsAd={
                        <SearchForm
                          ecId={`${
                            (this && this.props && this.props.ecId) || ''
                          }_SearchForm@c1du5c@searchad`}
                          conditioninfo={conditioninfo}
                          form={coworkMainStore.content.searchForm}
                          initFunc={form => (this.searchForm = form)}
                          onEnterSearch={this.search}
                        />
                      }
                      buttonsAd={[
                        <Button
                          ecId={`${
                            (this && this.props && this.props.ecId) || ''
                          }_Button@pvo8ez@search`}
                          type="primary"
                          onClick={this.search}
                        >
                          {getLabel(197, '搜索')}
                        </Button>,
                        <Button
                          ecId={`${
                            (this && this.props && this.props.ecId) || ''
                          }_Button@vunv7i@reset`}
                          type="ghost"
                          onClick={this.resetSearch}
                        >
                          {getLabel(2022, '重置')}
                        </Button>,
                        <Button
                          ecId={`${
                            (this && this.props && this.props.ecId) || ''
                          }_Button@uhybve@cancel`}
                          type="ghost"
                          onClick={() => this.setShowSearchAd(false)}
                        >
                          {getLabel(201, '取消')}
                        </Button>,
                      ]}
                    />
                    <div className="tabContent">
                      {tabKey == 'list' ? (
                        <ReplyList
                          ecId={`${
                            (this && this.props && this.props.ecId) || ''
                          }_ReplyList@irmpiv@${tabKey}`}
                          batchOperate={batchOperate}
                          ref="replyList"
                          submit={this.submit}
                          itemapprovalAtatus={itemsVO.approvalAtatus}
                          isCanAnonymous={itemsVO.isAnonymous}
                          canReply={canReply}
                          coworkId={coworkContentId}
                          scrollToTop={this.scrollToTop}
                        />
                      ) : tabKey == 'my' ? (
                        <MyReplyList
                          ecId={`${
                            (this && this.props && this.props.ecId) || ''
                          }_MyReplyList@fek1nq@${tabKey}`}
                          ref="my"
                          submit={this.submit}
                          coworkId={coworkContentId}
                          scrollToTop={this.scrollToTop}
                          canReply={canReply}
                          isCanAnonymous={itemsVO.isAnonymous}
                        />
                      ) : tabKey == 'stat' ? (
                        <Stat
                          ecId={`${
                            (this && this.props && this.props.ecId) || ''
                          }_Stat@wkfa5w@${tabKey}`}
                          coworkId={coworkContentId}
                          onCoverageViewMore={this.onCoverageViewMore}
                          onJoinViewMore={this.onJoinViewMore}
                        />
                      ) : (
                        <Resource
                          ecId={`${
                            (this && this.props && this.props.ecId) || ''
                          }_Resource@ck8kpw@${tabKey}`}
                          coworkId={coworkContentId}
                        />
                      )}
                    </div>
                  </div>
                </WeaNewScroll>
              </div>
            </div>,

            (tabKey == 'list' || tabKey == 'my') && (
              <div className="fixPagination">
                {tabKey == 'list' && batchOperate && (
                  <div className="fix-front">
                    <WeaCheckbox
                      ecId={`${
                        (this && this.props && this.props.ecId) || ''
                      }_WeaCheckbox@xal0p9@checkAll`}
                      onChange={coworkMainStore.checkAll}
                      value={checkAll}
                    />
                    <span className="ml5">{getLabel(556, '全选')}</span>
                    <Button
                      ecId={`${
                        (this && this.props && this.props.ecId) || ''
                      }_Button@cbxhnp@delete`}
                      type="primary"
                      className="ml20"
                      onClick={this.batchDelete}
                    >
                      {getLabel(32136, '批量删除')}
                    </Button>
                    {pendApprove && (
                      <Button
                        ecId={`${
                          (this && this.props && this.props.ecId) || ''
                        }_Button@usul3l@approval`}
                        type="primary"
                        className="ml10"
                        onClick={this.batchApprove}
                      >
                        {getLabel(83212, '批量批准')}
                      </Button>
                    )}
                  </div>
                )}
                <Pagination
                  ecId={`${
                    (this && this.props && this.props.ecId) || ''
                  }_Pagination@congva@pagination`}
                  {...page}
                  showQuickJumper={true}
                  onChange={this.changePage}
                />
              </div>
            ),
            <CoworkFloorDialog
              ecId={`${
                (this && this.props && this.props.ecId) || ''
              }_CoworkFloorDialog@7mds0h@dialog`}
              ref="floor"
            />,
          ]
        ) : con && con.isquit && con.viewRight !== 1 ? (
          <WeaAlertPage
            ecId={`${
              (this && this.props && this.props.ecId) || ''
            }_WeaAlertPage@sqgcsx`}
          >
            <div>{getLabel('513340', '您已退出该协作！')}</div>
          </WeaAlertPage>
        ) : (
          <WeaAlertPage
            ecId={`${
              (this && this.props && this.props.ecId) || ''
            }_WeaAlertPage@2c5yj2`}
          >
            <div>{getLabel(382663, '暂无权限')}</div>
          </WeaAlertPage>
        )}
        <NewCowork
          ecId={`${
            (this && this.props && this.props.ecId) || ''
          }_NewCowork@x4ukbc`}
          storeMapKey={storeMapKey}
          saveCallback={this.saveCallback}
          needCbDelay
        />
        {this.state.participationVisible && (
          <Participation
            ecId={`${
              (this && this.props && this.props.ecId) || ''
            }_Participation@vpudox`}
            visible={this.state.participationVisible}
            onCancel={this.onParticipationCancel}
            id={coworkContentId}
            store={participationStore}
            type={this.state.participationType}
          />
        )}
        <LogDialog
          ecId={`${
            (this && this.props && this.props.ecId) || ''
          }_LogDialog@1e4owx`}
          visible={this.state.visiable}
          id={coworkContentId}
          showLogDialog={bool => this.showLogDialog(bool)}
        />
        <InvitedDialog
          ecId={`${
            (this && this.props && this.props.ecId) || ''
          }_InvitedDialog@dxph3v`}
          visible={this.state.invitedVisible}
          onCancel={this.onInvitedCancel}
          submitParams={
            itemsVO ? { id: itemsVO.id, typeId: itemsVO.typeid } : {}
          }
          submit={this.onInvitedSubmit}
        />
      </div>
    );
  }

  onInvitedCancel = () => this.setState({ invitedVisible: false });
  onInvitedSubmit = () => {
    const { coworkMainStore } = this.props;
    coworkMainStore.getShareConditionStrList();
    coworkMainStore.reloadLeftList();
    coworkMainStore.reloadCowork();
  };

  onParticipationCancel = () => this.setState({ participationVisible: false });

  setEllipse = (flag) => {
    let { setStoreState } = this.props.coworkMainStore;
    setStoreState({ isEllipse: flag });
  };

  // 标星
  mark = (item) => {
    let { content, markItemAsType } = this.props.coworkMainStore;
    markItemAsType({ coworkids: content.id, type: item.key });
  };

  // 编辑
  edit = () => {
    // storeMapKey通过Detail页面传进来
    const coworkNewStore = this.props.coworkStoreMap.getMapStore(storeMapKey);
    coworkNewStore.doEditInit();
  };

  onCoverageViewMore = () => {
    // storeMapKey通过Detail页面传进来
    const coworkNewStore = this.props.coworkStoreMap.getMapStore(storeMapKey);
    coworkNewStore.doEditInit(1, { table_nocheck: 1 });
  };

  onJoinViewMore = (type = '') => {
    this.setState({ participationVisible: true, participationType: type });
  };

  // 查看日志
  showLogDialog = (bool) => {
    this.setState({
      visiable: bool,
    });
  };

  // 退出协作
  quitCowork = () => {
    let { quitCowork } = this.props.coworkMainStore;
    Modal.confirm({
      content: (
        <div style={{ textAlign: 'center' }}>
          <p>{getLabel('513247', '确定要退出协作吗？')}</p>
          <p style={{ color: 'red' }}>
            {getLabel('513248', '（退出后需要联系负责人进行操作才可再次加入）')}
          </p>
        </div>
      ),
      onOk() {
        quitCowork();
      },
    });
  };

  operateCoworkItem = (id, type) => {
    let { operateCoworkItem } = this.props.coworkMainStore;
    if (type == 'end') {
      Modal.confirm({
        content: getLabel(4910, '确认要结束该协作吗?', 'note'),
        onOk() {
          operateCoworkItem && operateCoworkItem(id, type);
        },
      });
    } else if (type === 'open') {
      Modal.confirm({
        content: getLabel(512602, '确认要打开该协作吗?'),
        onOk() {
          operateCoworkItem && operateCoworkItem(id, type);
        },
      });
    } else if (type === 'invite') {
      // 邀请加入
      this.setState({ invitedVisible: true });
    } else {
      operateCoworkItem && operateCoworkItem(id, type);
    }
  };

  // 红点显示隐藏
  dotClick = () => {
    this.props.coworkMainStore.setCoworkRead();
  };

  setShowSearchAd = (bool) => {
    // this.setState({
    //   showSearchAd: bool
    // });
    this.props.coworkMainStore.setDetailParams({ showSearchAd: bool });
  };

  changeTabKey = (tabKey) => {
    const {
      coworkMainStore: { setContentParams },
    } = this.props;
    setContentParams({
      page: {
        current: 1,
        total: 0,
        pageSize: 20,
      },
    });
    this.resetSearch();
    this.setShowSearchAd(false);
    this.props.coworkMainStore.setDetailParams({ tabKey });
  };

  changePage = (current) => {
    // let {tabKey} = this.state;
    const { tabKey } = this.props.coworkMainStore.detailParams;
    if (tabKey == 'list') {
      this.refs.replyList &&
        this.refs.replyList.wrappedInstance.changePage(current);
    } else {
      this.refs.my && this.refs.my.wrappedInstance.changePage(current);
    }
  };

  submitInEdit = (params, callback) =>
    this.submit(
      params,
      this.cancel(() => {
        isFunction(callback) && callback();
        this.changeTabKey('list');
      }),
    );

  submit = (params, callback) => {
    if (!params.remark) {
      message.error(getLabel(382648, '请输入交流内容'));
      return false;
    }
    const { coworkMainStore } = this.props;
    // const {tabKey} = this.state;
    const { tabKey } = coworkMainStore.detailParams;
    return coworkMainStore.submitCoworkDiscuss(params, tabKey, callback);
  };

  cancel = (callback) => {
    this.props.coworkMainStore.setDetailParams({ edit: false });
    this.refs.richText && this.refs.richText.wrappedInstance.clear();
    isFunction(callback) && callback();
  };

  batchDelete = () => {
    let that = this;
    const { coworkMainStore } = this.props;
    let checkIds = coworkMainStore.content.checkIds;
    if (checkIds && checkIds.length > 0) {
      Modal.confirm({
        content: (
          <div className="wea-list-confirm">
            <p>{getLabel(4912, '确认要删除这些讨论记录吗?', 'note')}</p>
            <div className="list-confirm-text">
              <WeaCheckbox
                ecId={`${
                  (this && this.props && this.props.ecId) || ''
                }_WeaCheckbox@mjqwl5`}
                onChange={this.valueChange}
                value={that.state.value}
              />
              {getLabel(4828, '同时删除该帖子的所有评论?', 'note')}
            </div>
          </div>
        ),
        onOk() {
          let { value } = that.state;
          coworkMainStore.batchDelete(value);
        },
      });
    } else {
      message.info(getLabel(84534, '请先选择要删除的记录'));
    }
  };

  valueChange = (value) => {
    this.setState({
      value,
    });
  };

  batchApprove = () => {
    const { coworkMainStore } = this.props;
    let checkIds = coworkMainStore.content.checkIds;
    if (checkIds && checkIds.length > 0) {
      coworkMainStore.batchApprove();
    } else {
      message.info(getLabel(4913, '请先选择要批准的记录?', 'note'));
    }
  };

  setPendApprove = () => {
    const { coworkMainStore } = this.props;
    coworkMainStore.setPendApprove();
  };

  baseSearch = (value) => {
    const { coworkMainStore } = this.props;
    coworkMainStore.searchDiscussList({ srchcontent: value });
    this.setShowSearchAd(false);
  };

  search = () => {
    const { coworkMainStore } = this.props,
      searchForm = coworkMainStore.content.searchForm;
    coworkMainStore.searchDiscussList(searchForm.getFormParams());
    this.setShowSearchAd(false);
  };

  resetSearch = () => {
    this.searchForm && this.searchForm.clear();
  };

  onKeyDown = (e) => {
    if (e.altKey && e.keyCode == 71) {
      this.refs.floor.wrappedInstance.open();
    }
  };

  scrollToTop = () => {
    this.refs.scroll && this.refs.scroll.scrollerToTop();
  };
}

export default CoworkContent;
